package com.ruoyi.web.controller.kiku;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.kiku.domain.KikuRelationship;
import com.ruoyi.kiku.service.IKikuRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 关系中心Controller
 *
 * @author TT
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/kiku/relationship")
public class KikuRelationshipController extends BaseController
{
    @Autowired
    private IKikuRelationshipService kikuRelationshipService;

    /**
     * 查询关系中心列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationship:list')")
    @GetMapping("/list")
    public TableDataInfo list(KikuRelationship kikuRelationship)
    {
        startPage();
        List<KikuRelationship> list = kikuRelationshipService.selectKikuRelationshipList(kikuRelationship);
        return getDataTable(list);
    }

    /**
     * 导出关系中心列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationship:export')")
    @Log(title = "关系中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KikuRelationship kikuRelationship)
    {
        List<KikuRelationship> list = kikuRelationshipService.selectKikuRelationshipList(kikuRelationship);
        ExcelUtil<KikuRelationship> util = new ExcelUtil<KikuRelationship>(KikuRelationship.class);
        util.exportExcel(response, list, "关系中心数据");
    }

    /**
     * 获取关系中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationship:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(kikuRelationshipService.selectKikuRelationshipById(id));
    }

    /**
     * 新增关系中心
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationship:add')")
    @Log(title = "关系中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KikuRelationship kikuRelationship)
    {
        return toAjax(kikuRelationshipService.insertKikuRelationship(kikuRelationship));
    }

    /**
     * 修改关系中心
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationship:edit')")
    @Log(title = "关系中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KikuRelationship kikuRelationship)
    {
        return toAjax(kikuRelationshipService.updateKikuRelationship(kikuRelationship));
    }

    /**
     * 删除关系中心
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationship:remove')")
    @Log(title = "关系中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kikuRelationshipService.deleteKikuRelationshipByIds(ids));
    }
}
